<template>
  <view class="start-pairing-container">
    <!-- 状态栏占位 -->
    <view class="status-bar" :style="{height: statusBarHeight + 'px'}"></view>
    
    <!-- 顶部导航栏 -->
    <view class="pairing-navbar">
      <view class="navbar-content">
        <view class="nav-left" @click="goBack">
          <text class="back-icon">‹</text>
        </view>
        <text class="nav-title">开始配对</text>
        <view class="nav-right">
          <view class="nav-action-btn">
            <text class="action-dots">⋯</text>
          </view>
          <view class="nav-action-btn">
            <text class="action-location">📍</text>
          </view>
        </view>
      </view>
    </view>

    <!-- 内容区域 -->
    <view class="content-area">
      <!-- 搜索状态 -->
      <view v-if="!pairingSuccess" class="searching-state">
        <view class="bluetooth-section">
          <view class="bluetooth-icon-large">
            <view class="bluetooth-circle">
              <text class="bluetooth-text">🔵</text>
            </view>
          </view>
          <text class="status-text">···正在寻找蓝牙设备···</text>
        </view>
      </view>

      <!-- 配对成功状态 -->
      <view v-if="pairingSuccess" class="success-state">
        <view class="bluetooth-section">
          <view class="bluetooth-icon-large">
            <view class="bluetooth-circle">
              <text class="bluetooth-text">🔵</text>
            </view>
          </view>
          <text class="status-text">已找到以下设备</text>
        </view>

        <!-- 设备信息 -->
        <view class="device-info">
          <text class="device-name">某品牌型号听诊宝</text>
          <view class="device-image">
            <view class="device-icon">📱</view>
          </view>
        </view>

        <!-- 操作按钮 -->
        <view class="action-buttons">
          <view class="primary-btn" @click="completePairing">
            <text class="btn-text">完成配对</text>
          </view>
          <view class="secondary-btn" @click="researchDevice">
            <text class="btn-text secondary">重新查找</text>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      statusBarHeight: 0,
      deviceType: '',
      pairingSuccess: false,
      searchTimer: null
    }
  },
  
  onLoad(options) {
    this.getSystemInfo()
    this.deviceType = options.deviceType || 'stethoscope'
    this.startSearching()
  },
  
  onUnload() {
    if (this.searchTimer) {
      clearTimeout(this.searchTimer)
    }
  },
  
  methods: {
    getSystemInfo() {
      const systemInfo = uni.getSystemInfoSync()
      this.statusBarHeight = systemInfo.statusBarHeight || 0
    },
    
    goBack() {
      uni.navigateBack()
    },
    
    startSearching() {
      this.pairingSuccess = false
      // 模拟搜索过程，2秒后显示配对成功
      this.searchTimer = setTimeout(() => {
        this.pairingSuccess = true
      }, 2000)
    },
    
    researchDevice() {
      this.startSearching()
    },
    
    completePairing() {
      uni.navigateTo({
        url: `/pages/deviceBound/index?deviceType=${this.deviceType}`
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.start-pairing-container {
  min-height: 100vh;
  background: #F5F5F5;
  position: relative;
}

.status-bar {
  background: #FFFFFF;
}

.pairing-navbar {
  background: #FFFFFF;
  height: 88rpx;
  border-bottom: 1px solid #E5E5E5;
  
  .navbar-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 100%;
    padding: 0 32rpx;
    
    .nav-left {
      width: 60rpx;
      height: 60rpx;
      display: flex;
      align-items: center;
      justify-content: center;
      
      .back-icon {
        font-size: 48rpx;
        color: #333333;
        font-weight: bold;
      }
    }
    
    .nav-title {
      font-size: 36rpx;
      font-weight: bold;
      color: #333333;
    }
    
    .nav-right {
      display: flex;
      align-items: center;
      
      .nav-action-btn {
        width: 60rpx;
        height: 60rpx;
        background: rgba(0, 0, 0, 0.05);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-left: 16rpx;
        
        .action-dots, .action-location {
          font-size: 24rpx;
          color: #666666;
        }
      }
    }
  }
}

.content-area {
  padding: 120rpx 32rpx 60rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.bluetooth-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 80rpx;
  
  .bluetooth-icon-large {
    margin-bottom: 40rpx;
    
    .bluetooth-circle {
      width: 200rpx;
      height: 200rpx;
      background: radial-gradient(circle, rgba(33, 150, 243, 0.2) 0%, rgba(33, 150, 243, 0.1) 50%, transparent 70%);
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      position: relative;
      
      &::before {
        content: '';
        position: absolute;
        width: 160rpx;
        height: 160rpx;
        border: 2rpx solid rgba(33, 150, 243, 0.3);
        border-radius: 50%;
        animation: pulse 2s infinite;
      }
      
      &::after {
        content: '';
        position: absolute;
        width: 120rpx;
        height: 120rpx;
        border: 2rpx solid rgba(33, 150, 243, 0.5);
        border-radius: 50%;
        animation: pulse 2s infinite 0.5s;
      }
      
      .bluetooth-text {
        font-size: 60rpx;
        color: #2196F3;
        z-index: 1;
      }
    }
  }
  
  .status-text {
    font-size: 32rpx;
    color: #666666;
  }
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(1.2);
    opacity: 0;
  }
}

.device-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 80rpx;
  
  .device-name {
    font-size: 36rpx;
    font-weight: bold;
    color: #333333;
    margin-bottom: 40rpx;
  }
  
  .device-image {
    width: 200rpx;
    height: 200rpx;
    background: #F5F5F5;
    border-radius: 20rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    
    .device-icon {
      font-size: 80rpx;
    }
  }
}

.action-buttons {
  width: 100%;
  
  .primary-btn {
    width: 100%;
    height: 96rpx;
    background: #2196F3;
    border-radius: 48rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 32rpx;
    
    .btn-text {
      font-size: 32rpx;
      color: #FFFFFF;
      font-weight: 500;
    }
  }
  
  .secondary-btn {
    width: 100%;
    height: 80rpx;
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    
    .btn-text {
      font-size: 28rpx;
      font-weight: 500;
      
      &.secondary {
        color: #2196F3;
        text-decoration: underline;
      }
    }
  }
}
</style> 